import { Component } from '@angular/core';
import {  NavController, NavParams, ViewController } from 'ionic-angular';
import { BatteryStatus } from '@ionic-native/battery-status';
/**
 * Generated class for the GetbatterystatusPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
    selector: 'page-getbatterystatus',
    templateUrl: 'getbatterystatus.html'
})
export class GetbatterystatusPage {
    public chooseType = 'handle';
    public batteryStatus: any = {};
    public subscription: any;
    public showArr = [
        {
            text: '1.ionic cordova plugin add cordova-plugin-battery-status',
            tips: '添加平台'
        },
        {
            text: '2.cnpm install --save @ionic-native/battery-status',
            tips: '安装依赖'
        }
    ];

    constructor(
        public navCtrl: NavController,
        public viewCtrl: ViewController,
        public navParams: NavParams,
        private batteryStatu: BatteryStatus
    ) {}
    dismiss() {
        this.viewCtrl.dismiss();
    }
    segmentChanged(e) {
        console.log(e);
        console.log(this.chooseType);
    }
    start() {
        this.subscription = this.batteryStatu.onChange().subscribe((status) => {
            console.log(status.level, status.isPlugged);
            this.batteryStatus.level = status.level;
            this.batteryStatus.isPlugged = status.isPlugged;
        });
    }
    stop() {
        this.subscription.unsubscribe();
    }
    ionViewDidEnter() {
        console.log('ionViewDidLoad GetbatterystatusPage');
        this.start();
    }
}
